var wxCommon = {

    /****是否开启在浏览器开发测试，提交代码的时候，或者在生产环境下必须设置为false****/
    enableWeb: false,

    init: function () {

        //引入外部文件
        this.setExternalFiles();

        //判断来源是否为saas
        this.isSaas = commonObj.get_param()["corpid"] && commonObj.get_param()["corpid"] != this.AppID;

        if (this.isSaas) {

            this.AppID = commonObj.get_param()["corpid"];
        }

        //获取微信用户信息
        if (!this.enableWeb) {

            this.getWxUserInfo();

        } else {

            /****开发人员进行开发时，把以下信息替换成本人信息****/

            this.WX_USER_INFO.USER_ID = "chenyibin";

            this.WX_USER_INFO.USER_NAME = "陈毅斌";

            this.WX_USER_INFO.MOBILE_PHONE = "15812820868";

            this.WX_USER_INFO.DEPARTMENT_ID = "40287d815bf6e76a015bf6e958fd0002";

            this.WX_USER_INFO.DEPARTMENT_NAME = "企业号开发组";

            this.WX_USER_INFO.CORP_ID = "wx8cc367ddb2dd803e";
        }

        //根据生产环境还是本地测试环境设置变量
        this.setExternalVars();
    },

    //AppID
    AppID: "wx8cc367ddb2dd803e",

    //CSS文件数组
    cssFileArr: [],

    //JS文件数组
    jsFileArr: [

        //微信JSSDK
        "/jijianzw/scripts/JSSDK/jweixin-1.2.0.js",

        //高德地图
        "http://webapi.amap.com/maps?v=1.3&key=cd5648802be9b274f2ecb012c5abbdd5",

        //fastclick
        "/jijianzw/scripts/jquery.event.special.fastclick/jquery.event.special.fastclick.js",

        //jquery.jSignature签名
        "/jijianzw/scripts/jquery.jSignature/jquery.jSignature.min.js",

        //Agile Lite框架
        "/jijianzw/scripts/jquery.mobile/jquery.mobile.custom.min.js",
        "/jijianzw/scripts/iscroll/iscroll.js",
        "/jijianzw/scripts/arttemplate/template-native.js",
        "/jijianzw/scripts/agile/agile.js",
        "/jijianzw/scripts/app/app.seedsui.js",

        //seedsui
        "/jijianzw/scripts/seedsui/seedsui.min.js",
    ],

    //引入CSS文件
    setCssFile: function (file_path) {
        var e = document.createElement("link");
        e.rel = "stylesheet";
        e.href = file_path;
        document.getElementsByTagName("head")[0].appendChild(e);
    },

    //引入JS文件
    setJsFile: function (file_path) {
        document.write("<script src='" + file_path + "'></script>");
    },

    //引入外部文件
    setExternalFiles: function () {
        var i;

        //引入JS文件
        for (i = 0; i < this.jsFileArr.length; i++) {
            this.setJsFile(this.jsFileArr[i]);
        }

        //引入CSS文件
        for (i = 0; i < this.cssFileArr.length; i++) {
            this.setCssFile(this.cssFileArr[i]);
        }
    },

    //根据生产环境还是本地测试环境设置变量
    setExternalVars: function () {

        if (window.location.host == "jijianzw.workmap.net.cn") {

            //生产环境

            //人员持证识别域名
            this.hostUrl.face_recognition = "http://183.63.70.10:9072"

        } else {

            //本地测试环境

            //人员持证识别域名
            this.hostUrl.face_recognition = "http://172.16.17.27:9072"
        }
    },

    //模块文件URL
    moduleUrl: {

        //搜索项目
        search_project: "/jijianzw/wx_end/module_search_project.html",

        //承包商列表
        select_contractor: "/jijianzw/wx_end/module_select_contractor.html",

        //人员违章扣分库
        person_illegal_problems: "/jijianzw/wx_end/module_person_illegal_problems.html",

        //承包商违章扣分库
        contractor_illegal_problems: "/jijianzw/wx_end/module_contractor_illegal_problems.html",

        //通讯录
        select_contact: "/jijianzw/wx_end/module_select_contact.html"
    },

    //通用域名URL
    hostUrl: {

        //人员持证识别
        face_recognition: ""
    },

    //需要用到的微信JS API
    jsApiList: [
        'checkJsApi',
        'onMenuShareTimeline',
        'onMenuShareAppMessage',
        'onMenuShareQQ',
        'onMenuShareWeibo',
        'onMenuShareQZone',
        'hideMenuItems',
        'showMenuItems',
        'hideAllNonBaseMenuItem',
        'showAllNonBaseMenuItem',
        'translateVoice',
        'startRecord',
        'stopRecord',
        'onVoiceRecordEnd',
        'playVoice',
        'onVoicePlayEnd',
        'pauseVoice',
        'stopVoice',
        'uploadVoice',
        'downloadVoice',
        'chooseImage',
        'previewImage',
        'uploadImage',
        'downloadImage',
        'getNetworkType',
        'openLocation',
        'getLocation',
        'hideOptionMenu',
        'showOptionMenu',
        'closeWindow',
        'scanQRCode',
        'chooseWXPay',
        'openProductSpecificView',
        'addCard',
        'chooseCard',
        'openEnterpriseContact',
        'openCard'
    ],

    //判断来源是否为saas
    isSaas: "",

    //微信用户信息
    WX_USER_INFO: {

        //微信用户id
        USER_ID: "",

        //微信用户手机号码
        MOBILE_PHONE: "",

        //微信用户姓名
        USER_NAME: "",

        //微信用户所属部门ID
        DEPARTMENT_ID: "",

        //微信用户部门名称
        DEPARTMENT_NAME: "",

        //微信用户所属企业号ID
        CORP_ID: "",

        //CODE
        CODE: "",

        //微信用户类型
        //USER_TYPE=1:监理
        //USER_TYPE=2:电建
        //USER_TYPE=3:业主
        //USER_TYPE为空的时候默认为业主
        USER_TYPE: ""
    },

    //获取微信用户信息
    getWxUserInfo: function () {

        var _this = this;

        if (!$.cookie("WX_USER_INFO.USER_ID") || ($.cookie("WX_USER_INFO.CORP_ID") != this.AppID)) {

            //cookies过期

            var code = commonObj.get_param()["code"];

            if ($.cookie("WX_USER_INFO.CODE")) {

                //code失效
                if (code == $.cookie("WX_USER_INFO.CODE")) {

                    commonObj.loadingBarShow("cookies过期，请关闭页面后重新进入");

                    window.setInterval(function () {
                        commonObj.loadingBarShow("cookies过期，请关闭页面后重新进入");
                    }, 40200);

                    return;
                }
            }

            $.cookie("WX_USER_INFO.CODE", code, {path: "/"});

            $.ajax({
                type: "post",
                dataType: "json",
                url: "/jijianzw/api/weixinController.do?wxlogin",
                cache: false,//不缓存
                async: true,
                data: {
                    code: code,
                    corpId: _this.isSaas ? _this.AppID : ""
                },
                success: function (data) {

                    //console.log(data);

                    if (data.statusCode == "0000") {

                        data = data.data;

                        _this.WX_USER_INFO.USER_ID = data.userid;

                        _this.WX_USER_INFO.USER_NAME = data.realname;

                        _this.WX_USER_INFO.MOBILE_PHONE = data.mobilephone;

                        _this.WX_USER_INFO.DEPARTMENT_ID = data.departid;

                        _this.WX_USER_INFO.DEPARTMENT_NAME = data.departname;

                        _this.WX_USER_INFO.CORP_ID = data.corpid;

                        _this.WX_USER_INFO.USER_TYPE = data.usertype;

                        //设置cookie有效时间为1小时
                        var cookie_time = new Date();

                        cookie_time.setTime(cookie_time.getTime() + (60 * 60 * 1000));

                        var cookie_prop = {
                            path: "/",
                            expires: cookie_time
                        };

                        $.cookie("WX_USER_INFO.USER_ID", _this.WX_USER_INFO.USER_ID, cookie_prop);
                        $.cookie("WX_USER_INFO.USER_NAME", _this.WX_USER_INFO.USER_NAME, cookie_prop);
                        $.cookie("WX_USER_INFO.MOBILE_PHONE", _this.WX_USER_INFO.MOBILE_PHONE, cookie_prop);
                        $.cookie("WX_USER_INFO.DEPARTMENT_ID", _this.WX_USER_INFO.DEPARTMENT_ID, cookie_prop);
                        $.cookie("WX_USER_INFO.DEPARTMENT_NAME", _this.WX_USER_INFO.DEPARTMENT_NAME, cookie_prop);
                        $.cookie("WX_USER_INFO.CORP_ID", _this.WX_USER_INFO.CORP_ID, cookie_prop);
                        $.cookie("WX_USER_INFO.USER_TYPE", _this.WX_USER_INFO.USER_TYPE, cookie_prop);

                        _this.wx_config();

                    } else {

                        commonObj.loadingBarShow("您还没有权限使用基建宝");

                        window.setInterval(function () {
                            commonObj.loadingBarShow("您没有权限使用基建宝");
                        }, 40200);
                    }
                }
            });

        } else {

            this.WX_USER_INFO.USER_ID = $.cookie("WX_USER_INFO.USER_ID");

            this.WX_USER_INFO.USER_NAME = $.cookie("WX_USER_INFO.USER_NAME");

            this.WX_USER_INFO.MOBILE_PHONE = $.cookie("WX_USER_INFO.MOBILE_PHONE");

            this.WX_USER_INFO.DEPARTMENT_ID = $.cookie("WX_USER_INFO.DEPARTMENT_ID");

            this.WX_USER_INFO.DEPARTMENT_NAME = $.cookie("WX_USER_INFO.DEPARTMENT_NAME");

            this.WX_USER_INFO.CORP_ID = $.cookie("WX_USER_INFO.CORP_ID");

            this.WX_USER_INFO.USER_TYPE = $.cookie("WX_USER_INFO.USER_TYPE");

            this.wx_config();
        }
    },

    //进行微信认证
    wx_config: function () {

        var _this = this;

        var code;
        code = commonObj.get_param()["code"];

        $.ajax({
            type: "post",
            dataType: "json",
            url: "/jijianzw/api/weixinController/getWXConfig.do",
            cache: false,//不缓存
            async: true,
            data: {
                userId: _this.WX_USER_INFO.USER_ID,
                corpId: _this.WX_USER_INFO.CORP_ID,
                url: encodeURIComponent(location.href.split('#')[0])
            },
            success: function (data) {

                //console.log(data);

                data = data.data;

                wx.config({
                    debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
                    appId: data.appId, // 必填，企业号的唯一标识，此处填写企业号corpid
                    timestamp: data.timestamp, // 必填，生成签名的时间戳
                    nonceStr: data.noncestr, // 必填，生成签名的随机串
                    signature: data.signature,// 必填，签名，见附录1
                    jsApiList: _this.jsApiList
                });
            }
        });
    },

    //微信认证成功
    wxReady: function (callback) {

        if (!this.enableWeb) {

            wx.ready(function () {

                //隐藏所有非基础按钮接口
                wx.hideAllNonBaseMenuItem();

                if (callback) {
                    callback();
                }
            });

        } else {

            if (callback) {
                callback();
            }
        }
    },

    usingScore: {

        //新增积分
        add: function (params) {

            var _this = this;

            if (wxCommon.WX_USER_INFO.USER_TYPE == "3") {

                $.ajax({
                    type: "post",
                    dataType: "json",
                    url: "/jijianzw/api/wxPerformanceController/savePerformance.do",
                    cache: false,//不缓存
                    async: true,
                    data: {
                        userId: params.userId,
                        departmentId: params.departmentId,
                        performanceStandardId: params.performanceStandardId,
                        projectId: params.projectId
                    },
                    success: function (data) {

                        //console.log(status_code);

                        switch (data.data.statusCode) {
                            case 0:
                                A.showToast("更新绩效积分失败");
                                break;

                            case 1:
                                A.showToast("您获得了" + _this.scoreArr[params.performanceStandardId] + "绩效积分");
                                break;

                            case 2:
                                A.showToast("该操作绩效积分已达当天上限");
                                break;

                            case 3:
                                A.showToast("今天重复签到/签出同一个项目，无法获得绩效积分");
                                break;
                        }
                    }
                });
            }
        },

        //积分表
        scoreArr: {

            //签到
            "1": 1,

            //签出
            "2": 1,

            //查看地图
            "3": 0.1,

            //查看统计报表
            "4": 0.1,

            //人员持证识别
            "5": 2,

            //人员违章登记
            "6": 3,

            //承包商违章登记
            "7": 5,

            //项目安全管理-查看
            "8": 0.1,

            //项目安全管理-录入/更新
            "9": 3,

            //承包商不良行为录入
            "10": 3,

            //施工设备管理-查看
            "11": 0.1,

            //施工设备管理-录入/更新
            "12": 3,

            //施工整改与回复
            "13": 3
        }

    },

    //回到基建宝主页
    to_homepage_link: function () {

        var redirect_url = "";

        if (this.isSaas) {

            //跳转到saas主页

            var str1 = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=";
            var str2 = "&redirect_uri=http://" + window.location.host + "/jijianzw/api/weixin/getJijianDianjianAuthorize.do%3Fcorpid%3D";
            var str3 = "%26urlIndex%3d";
            var str4 = "&response_type=code&scope=snsapi_base&state=1#wechat";

            redirect_url = str1 + this.AppID + str2 + this.AppID + str3 + "13" + str4;

        } else {

            //跳转到基建宝主页

            redirect_url = "http://" + window.location.host + "/jijianzw/api/weixinController/redirectWeixin.do?urlSelectIndex=0";
        }

        window.location.href = redirect_url;
    },

    //回到本功能首页
    to_index_page: function (element) {

        commonObj.back_to_top(element + " article");

        A.Controller.section(element);
    },

    //拼接各功能URL
    set_func_url: function (index, params) {

        var redirect_url = "";

        var params_str = "";

        if (params) {

            if (this.is_saas) {

                for (var i in params) {

                    params_str += "%26" + i + "%3d" + params[i];
                }

            } else {

                for (var i in params) {

                    params_str += "&" + i + "=" + params[i];
                }
            }
        }

        if (this.isSaas) {

            //跳转到saas功能

            var str1 = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=";
            var str2 = "&redirect_uri=http://" + window.location.host + "/jijianzw/api/weixin/getJijianDianjianAuthorize.do%3Fcorpid%3D";
            var str3 = "%26urlIndex%3d";
            var str4 = "&response_type=code&scope=snsapi_base&state=1#wechat";

            redirect_url = str1 + this.AppID + str2 + this.AppID + str3 + index + params_str + str4;


        } else {

            //跳转到企业号功能

            redirect_url = "http://" + window.location.host + "/jijianzw/api/weixinController/redirectWeixin.do?urlSelectIndex=" + index + params_str;
        }

        window.location.href = redirect_url;
    },

    //跳转到某些功能页面
    redirect: {

        map: function (id) {

            var tips_str = "跳转到地图后如果该对象不在地图上，请在搜索功能中搜索该对象。确定跳转到地图？";

            A.confirm("", tips_str,

                function () {

                    wxCommon.set_func_url(3, {

                        dataId: id
                    });
                },
                function () {

                    return false;
                }
            );
        }
    },

    //滚动列表回到顶部
    scrollList_back_to_top: function (element) {
        $(element).siblings("article").animate({scrollTop: 0}, 500);
    },

    //滚动列表
    scrollList: function (options) {

        var _this = this;

        //listId
        this.contentListId = $(options.contentListId) || null;

        //scrollListId
        this.scrollListId = options.scrollListId || null;

        //列表内容
        this.itemContent = options ? (options.itemContent || null) : null;

        //每次查询返回记录数
        this.pageSize = options.pageSize || 3;

        //记录序号
        this.order = 1;

        //当前页数
        this.pageNo = 1;

        //获取列表数据
        this.getListData = options ? (options.getListData || null) : null;

        //生成列表数据
        this.generateList = options.generateList || function (data) {

                //每次查询都要先清除“查看更多”按钮
                _this.contentListId.find(".result_item_more").remove();

                if (_this.pageNo == 1) {

                    _this.order = 1;

                    _this.contentListId.html("");

                    if (data.length == 0) {
                        var $temp_li = $("<li class='no_result'>没有相关数据</li>");
                        _this.contentListId.append($temp_li);
                        commonObj.loadingBarHide();
                        return;
                    }
                } else {
                    if (data.length == 0) {
                        commonObj.loadingBarHide();
                        return;
                    }
                }

                for (var i = 0; i < data.length; i++) {

                    var this_item = data[i];

                    if (_this.itemContent) {

                        var $temp_node = $('<li> <p class="history_head clear_float"><span class=""></span></p> <ul class="history_content"> </ul> </li>');

                        //标题
                        $temp_node.find(".history_head span").html(_this.order++ + "." + this_item.title).addClass(this_item.titleClass);

                        //列表内容
                        for (var j = 0; j < _this.itemContent.series.length; j++) {

                            var this_series_item = _this.itemContent.series[j];

                            var $temp_li = $('<li class="clear_float"> <span class="info_item_name"></span> <span class="info_item_content"></span> </li>');

                            $temp_li.find(".info_item_name").html(this_series_item.name).end().find(".info_item_content").html(this_item[this_series_item.id]);

                            $temp_node.find(".history_content").append($temp_li);
                        }

                        //绑定点击事件

                        //闭包
                        closureFunc(this_item);

                        function closureFunc(this_item) {

                            $temp_node.on("fastclick", function () {

                                var callbackParams = {};

                                if (_this.itemContent.control) {
                                    for (var j = 0; j < _this.itemContent.control.callbackParams.length; j++) {
                                        callbackParams[_this.itemContent.control.callbackParams[j]] = this_item[_this.itemContent.control.callbackParams[j]];
                                    }
                                }

                                _this.itemContent.control.callback(callbackParams);
                            });
                        }
                    }

                    _this.contentListId.append($temp_node);
                }

                if (data.length >= _this.pageSize) {

                    var $temp_li = $('<li class="result_item_more">往上拉查看更多</li>');

                    _this.contentListId.append($temp_li);
                }

                _this.pageNo++;

                _this.scrollListListener.scrollLock = 1;

                commonObj.loadingBarHide();
            };

        //重新加载滚动列表
        this.resetScrollList = function () {

            _this.pageNo = 1;

            _this.getListData();

            _this.scrollListListener.scrollToTop();
        };

        //滚动列表
        this.scrollListListener = new wxCommon.scrollListListener({
            scrollListId: this.scrollListId,
            scrollCallback: this.getListData.bind(this)
        });

    },

    //滚动列表监听器构造函数
    scrollListListener: function (options) {

        var _this = this;

        //scrollListId
        this.scrollListId = options.scrollListId;

        //回调函数
        this.scrollCallback = options.scrollCallback || null;

        //列表滚动锁键
        this.scrollLock = 1;

        //列表滚动监听
        this.listenScroll = function () {

            $(_this.scrollListId).scroll(function () {
                if ($(this).scrollTop() < 150) {
                    $(this).siblings(".back_top_btn").hide();
                } else {
                    $(this).siblings(".back_top_btn").show();
                }

                if (($(this).scrollTop() >= $(this).prop("scrollHeight") - $(window).height()) && _this.scrollLock) {

                    var $result_item_more = $(this).find(".result_item_more");

                    if ($result_item_more.length) {
                        _this.scrollLock = 0;
                        setTimeout(function () {

                            if (_this.scrollCallback) {
                                _this.scrollCallback();
                            }
                        }, 500);
                    }
                }
            });
        }();

        //滚动回到顶部
        this.scrollToTop = function () {
            $(_this.scrollListId).animate({scrollTop: 0}, 500);
        }
    },

    //回到顶部按钮监听
    listListenBackTopBtn: function (element) {

        $(element).scroll(function () {

            if ($(this).scrollTop() < 150) {
                $(this).siblings(".back_top_btn").hide();
            } else {
                $(this).siblings(".back_top_btn").show();
            }
        });
    },

    //滚动列表某项构造函数
    scrollListItemObj: function (options) {

        //标题
        this.title = options ? (options.title || "") : "";

        //标题的样式
        this.titleClass = options ? (options.titleClass || "text_white") : "text_white";
    },

    //时钟定时器
    intervalClockArr: {},

    //设置时钟定时器
    set_clock: function (element) {

        $(element).html(commonObj.get_format_date(new Date()));

        this.intervalClockArr[element] = window.setInterval(function () {
            $(element).html(commonObj.get_format_date(new Date()));
        }, 1000);
    },

    //清除时钟定时器
    clear_clock: function (element) {

        window.clearInterval(this.intervalClockArr[element]);
    },

    //获取用户当前定位
    user_location: {

        //地址容器
        element: null,

        //定位按钮
        btn: null,

        //初始化当前定位
        init: function (options) {

            this.element = options.element || null;
            this.btn = options.btn || null;
            this.auto = options.auto || false;

            if (this.auto) {

                this.wx_get_address();
            }
        },

        //手动定位到当前位置
        wx_get_address: function () {

            var _this = this;

            commonObj.loadingBarShow("正在定位");

            this.loadingLock = 1;

            //禁止定位过程中，多次点击重新定位按钮
            $(this.btn).unbind("click").on("click", this.forbid_location_again);

            wx.getLocation({
                type: 'gcj02', // 默认为wgs84的gps坐标，如果要返回直接给openLocation用的火星坐标，可传入'gcj02'
                success: function (res) {

                    _this.get_formatted_address(res);
                }
            });
        },

        //获取中文地址
        get_formatted_address: function (res) {

            var _this = this;

            $.ajax({
                type: "post",
                dataType: "json",
                url: "http://restapi.amap.com/v3/geocode/regeo?parameters",
                cache: false,//不缓存
                async: true,
                data: {
                    key: "81eaaa3373cf7db2f932147522829907",
                    location: res.longitude + "," + res.latitude
                },

                success: function (data) {

                    A.showToast("定位成功");

                    $(_this.element).text(data.regeocode.formatted_address).attr({
                        longtitude: res.longitude + "",
                        latitude: res.latitude + ""
                    });

                    if (_this.loadingLock) {
                        commonObj.loadingBarHide();
                    }

                    $(_this.btn).unbind("click").on("click", _this.wx_get_address.bind(_this));
                },

                error: function () {

                    A.showToast("定位失败");

                    $(this.element).text("获取地址失败");
                    commonObj.loadingBarHide();

                    $(this.btn).unbind("click").on("click", this.wx_get_address.bind(this));
                }
            });

            setTimeout(function () {
                commonObj.loadingBarHide();
            }, 5000);
        },

        //禁止定位过程中，多次点击重新地位按钮
        forbid_location_again: function () {
            A.alert("", "定位中，请稍候");
        }
    },

    //微信选取照片
    wx_post_images: function (show_img_box, amount) {

        var _this = this;

        amount = amount || 9;

        wx.chooseImage({
            count: amount, // 默认9
            sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
            sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
            success: function (res) {
                var localIds = res.localIds; // 返回选定照片的本地ID列表，localId可以作为img标签的src属性显示图片
                //console.log(localIds);

                for (var i = 0; i < localIds.length; i++) {

                    var $temp_node = $('<div class="img_wrap"> <a class="img_item" href="javascript:void(0)"> <img src="" alt=""/> </a> <a class="delete_img_btn" href="javascript:void(0)"></a> </div>');
                    $temp_node.find("img").attr({
                        "src": localIds[i],
                        "original_src": localIds[i],
                        "img_id": ""
                    });

                    show_img_box.append(_this.wx_bind_images_control($temp_node, show_img_box));
                }
            }
        });
    },

    //获取所有微信照片URL数组
    wx_get_all_images_list: function (img_box_node) {

        var url_list = [];

        img_box_node.find(".img_item img").each(function () {
            url_list.push($(this).attr("original_src"));
        });

        return url_list;
    },

    //获取需要上传的微信照片URL数组
    wx_get_upload_images_list: function (img_box_node) {

        var url_list = [];

        img_box_node.find(".img_item img").each(function () {
            if (($(this).attr("img_id")) == "") {
                url_list.push($(this).attr("original_src"));
            }
        });

        return url_list;
    },

    //绑定某张照片预览和图片删除
    wx_bind_images_control: function (img_wrap, img_box_node, deletePicUrl) {

        var _this = this;

        //绑定微信图片预览
        img_wrap.find(".img_item").on("click", function () {

            wx.previewImage({
                current: $(this).find("img").attr("original_src"), // 当前显示图片的http链接
                urls: _this.wx_get_all_images_list(img_box_node) // 需要预览的图片http链接列表
            });
        }).end().find(".delete_img_btn").on("click", function () {

            //绑定微信图片删除

            var $temp_this = $(this);

            A.confirm("", "确认删除？", function () {

                var $img_node = $temp_this.siblings(".img_item").find("img");

                var $parent_node = $temp_this.parent();

                if ($img_node.attr("img_id") != "") {

                    //删除数据库中的图片URL
                    $.ajax({
                        type: "post",
                        dataType: "json",
                        url: deletePicUrl,
                        cache: false,//不缓存
                        async: true,
                        data: {
                            imgId: $img_node.attr("img_id")
                        },
                        success: function (data) {

                            //删除硬盘上的图片
                            $.ajax({
                                type: "post",
                                dataType: "json",
                                url: "/jijianzw/api/weixinController.do?deletePic",
                                cache: false,//不缓存
                                async: true,
                                data: {
                                    src: $img_node.attr("src")
                                },
                                success: function (data) {

                                    $parent_node.remove();
                                }
                            });
                        }
                    });

                } else {
                    $parent_node.remove();
                }
            });
        });

        return img_wrap;
    },

    //上传微信照片
    wx_upload_images: function (localIds, callback) {

        var server_id_arr = [];

        if (localIds.length > 0) {

            wx_sync_upload_images(localIds);

        } else {

            if (callback) {
                callback(server_id_arr.join(","));
            }
        }

        //同步上传微信照片并获取server_id_arr
        function wx_sync_upload_images(localIds) {

            var localId = localIds.pop();
            wx.uploadImage({
                localId: localId, // 需要上传的图片的本地ID，由chooseImage接口获得
                isShowProgressTips: 1, // 默认为1，显示进度提示
                success: function (res) {
                    var serverId = res.serverId; // 返回图片的服务器端ID
                    server_id_arr.push(serverId);

                    if (localIds.length == 0) {

                        if (callback) {
                            callback(server_id_arr.join(","));
                        }
                    }

                    if (localIds.length > 0) {
                        wx_sync_upload_images(localIds);
                    }
                }
            });
        }
    },

    //微信选取一张照片
    wx_post_one_image: function (img_node, callback) {

        var _this = this;

        wx.chooseImage({
            count: 1, // 默认9
            sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
            sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
            success: function (res) {

                var localId = res.localIds[0]; // 返回选定照片的本地ID列表，localId可以作为img标签的src属性显示图片
                //console.log(localIds);

                img_node.attr({
                    "src": localId,
                    "original_src": localId,
                    "img_id": ""
                });

                _this.wx_preview_one_image(img_node);

                _this.wx_upload_one_image(localId, callback);
            }
        });
    },

    //微信绑定预览一张照片
    wx_preview_one_image: function (img_node) {

        var src = img_node.attr("src");

        img_node.off("click").on("click", function () {
            wx.previewImage({
                current: src, // 当前显示图片的http链接
                urls: [src] // 需要预览的图片http链接列表
            });
        });
    },

    //微信上传一张照片
    wx_upload_one_image: function (localId, callback) {

        wx.uploadImage({
            localId: localId, // 需要上传的图片的本地ID，由chooseImage接口获得
            isShowProgressTips: 1, // 默认为1，显示进度提示
            success: function (res) {

                if (callback) {
                    callback(res.serverId); // 返回图片的服务器端ID
                }
            }
        });
    },

    //绑定微信地图导航
    wx_navigate: function (latitude, longitude) {
        wx.openLocation({
            latitude: parseFloat(latitude), // 纬度，浮点数，范围为90 ~ -90
            longitude: parseFloat(longitude), // 经度，浮点数，范围为180 ~ -180。
            name: '请点击右侧绿色图标', // 位置名
            address: '即可调用APP开启导航或显示路线', // 地址详情说明
            //infoUrl: '', // 在查看位置界面底部显示的超链接,可点击跳转
            scale: 20 // 地图缩放级别,整形值,范围从1~28。默认为最大
        });
    },

    //签名
    jSignature: {

        //初始化签名容器
        init: function (container, reset) {

            var _this = this;

            container.show();

            //初始化
            if (container.find(".jSignature ").length <= 0) {

                container.jSignature("init", {
                        width: "100%",
                        height: "200px"
                    }
                );

                this.enable(container);

            } else {

                this.reset(container);
            }

            //配置重置按钮
            reset.off("tap").on("tap", function () {

                _this.reset(container);

                _this.enable(container);
            });
        },

        //清除签名
        reset: function (container) {

            container.jSignature("reset");
        },

        //显示签名
        setData: function (container, data) {

            container.jSignature("setData", data);
        },

        //输出签名
        getData: function (container) {

            var data = container.jSignature("getData", "image");

            data = "data:" + data.join(",");

            return data;
        },

        //开启签名
        enable: function (container) {

            container.jSignature("enable");
        },

        //关闭签名
        disable: function (container) {

            container.jSignature("disable");
        },

        //重新初始化
        reinit: function (container) {

            if (container.find(".jSignature ").length > 0) {

                this.reset(container);
                this.enable(container);
            }
        }
    }

};

wxCommon.init();